package com.bmps.springcloud.insuredmicroservice.callback.accept;
import com.bmps.springcloud.common.response.CloudPlatModel;
import com.bmps.springcloud.common.response.TaskResponseModel;
import com.bmps.springcloud.common.task.bean.RequestObject;
import com.bmps.springcloud.insuredmicroservice.service.cloudplatform.RiskSupport;

import java.util.HashSet;
import java.util.concurrent.Callable;
/**
 * 保盾云任务
 *
 * @author lyw
 * @date 2019/07/30
 */
public class CloudPlatformCallBack implements Callable<TaskResponseModel> {
    private String key;
    private RequestObject requestObject;
    private final RiskSupport riskSupport;

    public CloudPlatformCallBack(String key, RiskSupport riskSupport, RequestObject requestObject) {
        this.setKey(key);
        this.riskSupport = riskSupport;
        this.setRequestObject(requestObject);
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    private void setRequestObject(RequestObject requestObject) {
        this.requestObject = requestObject;
    }

    /**
     * Computes a result, or throws an exception if unable to do so.
     *
     * @return computed result
     */
    @Override
    @SuppressWarnings("unchecked")
    public TaskResponseModel call() {
       return riskSupport.riskInvoke(key, (HashSet<CloudPlatModel>) requestObject.getParams());
    }
}